package com.dark.aop.sleuth;

import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * http请求过滤器
 *
 * @author chengluchao
 * @Date: 2021/2/1 09:22
 * @since 1.1.12
 */
@WebFilter
@Configuration
public class HttpSleuthFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        try {
            TraceUtil.configRequestId(request, response);
            chain.doFilter(request, response);
        } finally {
            TraceUtil.clear();
        }
    }

    @Override
    public void destroy() {
    }

}